<?php

namespace App\Listeners;

use App\Events\ArticleViewEvent;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class ArticleViewListener implements ShouldQueue
{
    public $timeout = 60;
    /**
     * Create the event listener.
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     */
    public function handle(ArticleViewEvent $event): void
    {
        $category = $event->article->category ?? null;
        if (!$category) {
            return;
        }
        $category->increment('view_num');
    }
}
